package tk.mybatis.springboot;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.springboot.mapper.CountryMapper;
import tk.mybatis.springboot.model.Country;

import java.util.List;

/**
 * Spring Boot 启动类
 */
@SpringBootApplication
@MapperScan(value = {"tk.mybatis.springboot.mapper", "tk.mybatis.simple.mapper"}, nameGenerator = MapperNameGenerator.class)
public class MybatisSpringBootApplication implements CommandLineRunner {

    @Autowired
    private CountryMapper countryMapper;

    public static void main(String[] args) {
        SpringApplication.run(MybatisSpringBootApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        List<Country> list = countryMapper.selectAll();
        if (list != null) {
            System.out.println(list.size());
            for (Country c : list) {
                System.out.println("国家：" + c.getCountryname() + ", 代码：" + c.getCountrycode());
            }
        }
    }
}
